package com.spring.dive.a03method;

import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class GenericMethodTest {

    public static void main(String[] args) {
        GenericMethod<String> method = new GenericMethod("xiaoming");
        method.printMethod("String类型",1000);

        Integer integer = method.printMethodList(Arrays.asList(1, 2, 3, 4, 5));
        String string = method.printMethodList(Arrays.asList("1", "2", "3", "4", "6"));
        System.out.println("-------integer:"+integer);
        System.out.println("-------string:"+string);

    }
    // 3.泛型方法可以独立于泛型类，可以在普通类中存在
    public <E> E printMethodList(List<E> list) {
        return list.get(new Random().nextInt(list.size()));
    }

    // 4.泛型方法可以为static
    public static <E> E printMethodList2(List<E> list) {
        return list.get(new Random().nextInt(list.size()));
    }
}
